package com.ruoyi.web.controller.base;

import com.ruoyi.base.domain.BusWarnWarninfo;
import com.ruoyi.base.service.IBusWarnWarninfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 预警信息数据Controller
 * 
 * @author ruoyi
 * @date 2025-09-11
 */
@RestController
@RequestMapping("/base/warninfo")
public class BusWarnWarninfoController extends BaseController
{
    @Autowired
    private IBusWarnWarninfoService busWarnWarninfoService;

    /**
     * 查询预警信息数据列表
     */
    //@PreAuthorize("@ss.hasPermi('base:warninfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusWarnWarninfo busWarnWarninfo)
    {
        startPage();
        List<BusWarnWarninfo> list = busWarnWarninfoService.selectBusWarnWarninfoList(busWarnWarninfo);
        return getDataTable(list);
    }

    /**
     * 导出预警信息数据列表
     */
    //@PreAuthorize("@ss.hasPermi('base:warninfo:export')")
    @Log(title = "预警信息数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusWarnWarninfo busWarnWarninfo)
    {
        List<BusWarnWarninfo> list = busWarnWarninfoService.selectBusWarnWarninfoList(busWarnWarninfo);
        ExcelUtil<BusWarnWarninfo> util = new ExcelUtil<BusWarnWarninfo>(BusWarnWarninfo.class);
        util.exportExcel(response, list, "预警信息数据数据");
    }

    /**
     * 获取预警信息数据详细信息
     */
    //@PreAuthorize("@ss.hasPermi('base:warninfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(busWarnWarninfoService.selectBusWarnWarninfoById(id));
    }

    /**
     * 新增预警信息数据
     */
    //@PreAuthorize("@ss.hasPermi('base:warninfo:add')")
    @Log(title = "预警信息数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusWarnWarninfo busWarnWarninfo)
    {
        return toAjax(busWarnWarninfoService.insertBusWarnWarninfo(busWarnWarninfo));
    }

    /**
     * 修改预警信息数据
     */
    //@PreAuthorize("@ss.hasPermi('base:warninfo:edit')")
    @Log(title = "预警信息数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BusWarnWarninfo busWarnWarninfo)
    {
        return toAjax(busWarnWarninfoService.updateBusWarnWarninfo(busWarnWarninfo));
    }

    /**
     * 删除预警信息数据
     */
    //@PreAuthorize("@ss.hasPermi('base:warninfo:remove')")
    @Log(title = "预警信息数据", businessType = BusinessType.DELETE)
	@PostMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(busWarnWarninfoService.deleteBusWarnWarninfoByIds(ids));
    }

    @Log(title = "预警信息数据", businessType = BusinessType.DELETE)
    @PostMapping("/close/{ids}")
    public AjaxResult close(@PathVariable String[] ids)
    {
        return toAjax(busWarnWarninfoService.closeBusWarnWarninfoByIds(ids));
    }

    @Log(title = "预警信息数据", businessType = BusinessType.DELETE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody BusWarnWarninfo busWarnWarninfo)
    {
        return toAjax(busWarnWarninfoService.auditBusWarnWarninfoById(busWarnWarninfo.getId(),busWarnWarninfo.getStatus(),busWarnWarninfo.getRemark()));
    }

    @GetMapping("/statisTypeCount")
    public AjaxResult statisTypeCount(String startDay,String endDay)
    {
        List<Map> mapList = busWarnWarninfoService.statisTypeCount(startDay,endDay);
        return AjaxResult.success(mapList);
    }

    @GetMapping("/statisTypeAndTimeCount")
    public AjaxResult statisTypeAndTimeCount(String startDay,String endDay)
    {
        Map map = busWarnWarninfoService.statisTypeAndTimeCount(startDay,endDay);
        return AjaxResult.success(map);
    }

    @GetMapping("/statisStatusCount")
    public AjaxResult statisStatusCount(String startDay,String endDay)
    {
        Map map = busWarnWarninfoService.statisStatusCount(startDay,endDay);
        return AjaxResult.success(map);
    }

    @GetMapping("/statisWarnLevelCount")
    public AjaxResult statisWarnLevelCount(String startDay,String endDay)
    {
        Map map = busWarnWarninfoService.statisWarnLevelCount(startDay,endDay);
        return AjaxResult.success(map);
    }
}
